import java.util.List;

public class SalesPromotion {
    private String type;
    private String displayName;
    private List<String> relatedItems;
    private ItemRepository itemRepository = new ItemRepositoryTestImpl();

    public SalesPromotion(String type, String displayName, List<String> relatedItems) {
        this.type = type;
        this.displayName = displayName;
        this.relatedItems = relatedItems;
    }

    public String getType() {
        return type;
    }

    public String getDisplayName() {
        return displayName;
    }

    public List<String> getRelatedItems() {
        return relatedItems;
    }

    public String getPromotionTitle() {
        if (type.equals("BUY_30_SAVE_6_YUAN")){
            return "\nPromotion used:\n满30减6 yuan";
        }else {
            return String.format("\nPromotion used:\nHalf price for certain dishes (%s)",
                    getPromotionList());
        }
    }

    private String getPromotionList() {
        return String.join("，",itemRepository.findAll().stream()
                .map(item -> relatedItems.contains(item.getId()) ? item.getName() : "")
                .filter(str -> !str.isEmpty()).toArray(String[]::new));
    }
}
